package org.moonholder.springboot.damocles.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationListener;
import org.springframework.security.web.session.HttpSessionDestroyedEvent;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * 监听session失效事件
 */
@Component
@Slf4j
class SessionDestroyedEventListener implements ApplicationListener<HttpSessionDestroyedEvent> {

    @Resource
    private SessionManage sessionManage;

    @Override
    public void onApplicationEvent(HttpSessionDestroyedEvent event) {
        String sessionId = event.getSession().getId();
        log.info("失效session:{}", sessionId);
        try {
            // 移除session
//            sessionManage.getHttpSessionMap().
        } catch (Exception e) {
            log.error(String.format("失效session:[%s]发生异常.", event.getId()), e);
        }
    }
}